package com.hwua.entity;

import java.util.List;

public class PageEntity {
    private Long totalRecords;//总记录数
    private int totalPages;//中页数
    private int pageSize;//每页显示的记录数
    private int pageNo;//当前页
    private int prePage;//上一页
    private int nextPage;//下一页
    private List<Product> list = null;//当前页要显示的记录集合.
    private List<Comment> list2=null;

    public List<Comment> getList2() {
        return list2;
    }

    public void setList2(List<Comment> list2) {
        this.list2 = list2;
    }

    public Long getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(Long totalRecords) {
        this.totalRecords = totalRecords;
    }

    /**
     * 得到总页数
     *
     * @return
     */
    public int getTotalPages() {
        //比如totalRecords=12  pageSize=5
        totalPages = (int) (totalRecords / pageSize);
        if (totalRecords % pageSize != 0) {
            totalPages += 1;
        }
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    /**
     * 获得上一页
     *
     * @return
     */
    public int getPrePage() {
        if (pageNo <= 1) {
            prePage = 1;
        } else {
            prePage = pageNo - 1;
        }
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    /**
     * 得到下一页
     *
     * @return
     */
    public int getNextPage() {
        if (pageNo >= getTotalPages()) {
            nextPage = getTotalPages();
        } else {
            nextPage = pageNo + 1;
        }
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public List<Product> getList() {
        return list;
    }

    public void setList(List<Product> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageEntity{" +
                "totalRecords=" + totalRecords +
                ", totalPages=" + totalPages +
                ", pageSize=" + pageSize +
                ", pageNo=" + pageNo +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                ", list=" + list +
                ", list2=" + list2 +
                '}';
    }
}
